﻿using System;
using System.Composition.Hosting;
using Unread.Business.Services.Interfaces;
using Unread.Notifications.Services.Interfaces;

namespace Unread.BackgroundTasks
{
    public static class ServicesFactory
    {
        private static CompositionHost _compositionHost;
        private static CompositionHost CompositionHost
        {
            get
            {
                if (_compositionHost == null) 
                    throw new InvalidOperationException("Call Initialize first, before using ServicesFactory");

                return _compositionHost;
            }
            set
            {
                _compositionHost = value;
            }
        }

        public static void Initialize(object compositionHost)
        {
            if (compositionHost as CompositionHost == null) throw new ArgumentNullException("compositionHost");

            CompositionHost = compositionHost as CompositionHost;
        }

        public static object GetUnreadFeedItemLoader()
        {
            return CompositionHost.GetExport<IUnreadFeedItemLoader>();
        }

        public static object GetTileUpdater()
        {
            return CompositionHost.GetExport<ITileUpdater>();
        }

        public static object GetSecondaryTileUpdater()
        {
            return CompositionHost.GetExport<ISecondaryTileUpdater>();
        }
    }
}
